package com.hanrui.android.activity.work;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hanrui.android.R;
import com.hanrui.android.adapter.ArchivesCheckAdapter;
import com.hanrui.android.library.base.ActionBarBaseActivity;
import com.hanrui.android.model.ArchivesCheckBean;
import com.hanrui.android.net.contract.work.ArchivesCheckContract;
import com.hanrui.android.net.presenter.work.ArchivesCheckPresenter;
import com.hanrui.android.widget.SearchEditText;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 员工档案查看
 */
public class ArchivesCheckActivity extends ActionBarBaseActivity<ArchivesCheckPresenter> implements ArchivesCheckContract.View, BaseQuickAdapter.OnItemClickListener {

    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;
    @Inject
    ArchivesCheckAdapter adapter;
    @BindView(R.id.searchEditText)
    SearchEditText searchEditText;

    String name = "";

    @Override
    protected void initInjector() {mActivityComponent.inject(this);}


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_mobile);

        unbinder = ButterKnife.bind(this);

        initView();
    }

    private void initView() {

        mTitleBar.setTitle("档案查看");

        setIsPullRefresh(true);

        setRefreshing();
        mPresenter.refresh(this,name);


        setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

                name = "";
                mPresenter.refresh(ArchivesCheckActivity.this,name);

            }
        });


        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setAdapter(adapter);
        adapter.setEmptyView(getNoDataView(mRecyclerView));
        adapter.setEnableLoadMore(false);
        adapter.setOnItemClickListener(this);


        searchEditText.setOnSearchClickListener(new SearchEditText.OnSearchClickListener() {
            @Override
            public void onSearchClick(View view, String keyword) {

                name = searchEditText.getText().toString();
                mPresenter.refresh(ArchivesCheckActivity.this,name);

            }
        });
    }

    @Override
    public void employeeList(List<ArchivesCheckBean.EmployeeListBean> dataList,int loadType) {

        setLoadDataResult(adapter,dataList, loadType,false);


    }


    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

        ArchivesCheckBean.EmployeeListBean bean = (ArchivesCheckBean.EmployeeListBean) adapter.getItem(position);
        ArchivesCheckDetailActivity.start(ArchivesCheckActivity.this,bean.getId());



    }

    public static void start(Context context){

        Intent intent = new Intent(context,ArchivesCheckActivity.class);
        context.startActivity(intent);

    }

}
